﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using JCTimes.DomainModel.Views;
using JCTimes.EFRepository.Specification;
using JCTimes.Portal.Infrastructure;
using System.Data.SqlClient;

namespace JCTimes.Portal.Specification
{
    public class PDASpecification
    {
        public static Expression<Func<V_PDA, bool>> Get_V_PDA_Pred(Searcher searcher)
        {
            Specification<V_PDA> spec = new TrueSpecification<V_PDA>();
            foreach (var key in searcher.Keys)
            {
                switch (key)
                {
                    case "pdano":
                        string pdano = searcher[key].Trim();
                        spec &= new DirectSpecification<V_PDA>(x => x.PDANo != null && x.PDANo.Contains(pdano));
                        break;
                    case "status":
                        int status =Convert.ToInt32( searcher[key].Trim());
                        spec &= new DirectSpecification<V_PDA>(x => x.Status!=null && x.Status== status);
                        break;
                    case "createusersid":
                        string createuserid = searcher[key].Trim();
                        spec &= new DirectSpecification<V_PDA>(x => x.CreateUsersID != null && x.CreateUsersID==createuserid);
                        break;
                    case "usersid":
                        string usersid = searcher[key].Trim();
                        spec &= new DirectSpecification<V_PDA>(x => x.UsersID != null && x.UsersID==usersid);
                        break;
                    default:
                        break;
                }
            }

            return spec.SatisfiedBy();
        }
    }
}